package com.cs.controller;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

//import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//@CrossOrigin
@RestController
public class MockSleep {

	@RequestMapping("/mocksleep")
	public Map<String, Object> sleep(Long time) {
		if(time == null) {
			time = (long) new Random().nextInt(5000);
		}
		Map<String, Object> result = new HashMap<>();
		result.put("code", 0);
		result.put("time", time);
		try {
			Thread.sleep(time);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result.put("code", 1);
			result.put("msg", e.toString());
		}
		return result;
	}
}
